package com.fl.serivce;

import org.apache.log4j.Logger;

import com.fl.common.ContentConstans;
import com.fl.dao.ParamDao;
import com.fl.sys.SysConfig;
import com.fl.util.MailUtil;

/**
 * 邮件发送服务，根据数据库邮件列表发送邮件
 * 
 * @author liliang
 * 
 */
public class MailService {

	private static Logger log = Logger.getLogger(MailService.class);

	public static void sendMail(String content) throws Exception {

		log.info("start to get mail config.");

		String mailServer = ParamDao.getParamTableVal(SysConfig.MAIL_SERVER);
		String mailUser = ParamDao.getParamTableVal(SysConfig.MAIL_USER);
		String mailPasswd = ParamDao.getParamTableVal(SysConfig.MAIL_PASSWD);
		String mailList = ParamDao.getParamTableVal(SysConfig.MAIL_LIST);

		log.info("get mail config sucessful,start to send mails to ["
				+ mailList + "] ");

		String[] toMails = mailList.split(";");
		for (String toMail : toMails) {
			MailUtil.sendMail(mailUser, toMail, mailUser, mailPasswd,
					mailServer, ContentConstans.MAIL_SUBJECT_CONTENT, content,
					null);
		}
		
		log.info("send mails successful.");
	}

}
